__author__="Yakovenko Kirill"
__date__ ="$08.05.2009$"

import wx

class MainWindow(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
        self.__loadIcons()
        self.__createWindow()
        self.__createTray()
    def __createTray(self):
        self.__trayIcon = wx.TaskBarIcon()
        wx.EVT_TASKBAR_LEFT_DCLICK(self.__trayIcon, self.OnTaskBarActivate)
        wx.EVT_TASKBAR_RIGHT_UP(self.__trayIcon, self.OnTaskBarMenu)
        wx.EVT_MENU(self.__trayIcon, self.TBMENU_SHOW, self.visible)
        #wx.EVT_MENU(self.__trayIcon, self.TBMENU_HIDE, self.OnTaskBarHide)
        #wx.EVT_MENU(self.__trayIcon, self.TBMENU_CLOSE, self.OnTaskBarClose)
    def visible(self):
        self.Show(True)
        self.__trayIcon.RemoveIcon()

    TBMENU_SHOW = 1000
    TBMENU_HIDE = 1001
    TBMENU_CLOSE = 1002
    def OnTaskBarMenu(self, evt):
        menu = wxMenu()
        #menu.Append(self.TBMENU_HIDE, "&Hide Mailwatcher")
        #menu.Append(self.TBMENU_SHOW, "&Show Mailwatcher")
        menu.Append(self.TBMENU_CLOSE,   "&Close")
        self.__trayIcon.PopupMenu(menu)
        menu.Destroy()

    def OnTaskBarActivate(self, evt):
        if not self.IsShown():
            self.Show(true)

    def __createWindow(self):
        pane = wx.FlexGridSizer(cols = 2)
        self.SetIcon(self.__disableIcon)
        pane.AddGrowableCol(1)
        pane.Add(wx.StaticText(self, -1, "Login:"), flag = wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border = 1)
        self.__loginText = wx.TextCtrl(self, wx.NewId(), "Your login here")
        pane.Add(self.__loginText, flag = wx.EXPAND)
        pane.Add(wx.StaticText(self, -1, "Password:"), flag = wx.ALIGN_CENTER_VERTICAL | wx.LEFT, border = 1)
        self.__passwordText = wx.TextCtrl(self, wx.NewId(), "Your password here")
        pane.Add(self.__passwordText, flag = wx.EXPAND)
        pane.Add(wx.StaticText(self, -1, ""))
        buttonsSizer = wx.BoxSizer()
        self.__startButton = wx.Button(self, wx.NewId(), "Start")
        self.__stopButton = wx.Button(self, wx.NewId(), "Stop")
        buttonsSizer.Add(self.__startButton, flag = wx.TOP | wx.RIGHT, border = 2)
        buttonsSizer.Add(self.__stopButton, flag = wx.TOP | wx.LEFT, border = 2)
        wx.EVT_BUTTON(self.__startButton, self.__startButton.Id, self.start)
        wx.EVT_BUTTON(self.__stopButton, self.__stopButton.Id, self.stop)
        pane.Add(buttonsSizer, flag = wx.ALIGN_RIGHT)
        self.SetSizer(pane)
        self.SetSize((350, 95))
        self.Centre()
        self.Layout()
    def start(self, event):
        wait = wx.StockCursor(wx.CURSOR_WATCH)
        topWin = wx.App().GetTopWindow()
        topWin.Enable(False)
        topWin.SetCursor(wait)
        #test net and start service
        #add message in tray
        topWin.SetCursor(wx.NullCursor)
        topWin.Enable(True)
    def stop(self, event):
        pass
    def __loadIcons(self):
         self.__enableIcon = wx.Icon("images/enable.ico", wx.BITMAP_TYPE_ICO)
         self.__disableIcon = wx.Icon("images/disable.ico", wx.BITMAP_TYPE_ICO)

if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    mainWnd = MainWindow(None, -1, "Autorization")
    mainWnd.Show(True)
    app.MainLoop()